package com.liukai.bishe.ui.dialog;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.liukai.bishe.R;
import com.liukai.bishe.model.doman.transaction.Transaction;
import com.liukai.bishe.model.doman.transaction.TransactionUseTime;
import com.liukai.bishe.presenter.transactionPresenter.ITransactionPresenter;
import com.liukai.bishe.utils.Constants;
import com.liukai.bishe.utils.DateUtils;
import com.liukai.bishe.utils.ToastUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TransactionDetailsDialog implements View.OnClickListener {

    private Context mContext;

    private AlertDialog mDialog = null;
    private final View mView_dialog;

    private TransactionUseTime mTransactionUseTime;
    private TextView mTvTitle;
    private TextView mTvStartTime;
    private TextView mTvStopTime;
    private TextView mTvTotalTime;


    public TransactionDetailsDialog(Context context, TransactionUseTime transactionUseTime){

        this.mContext = context;
        this.mTransactionUseTime = transactionUseTime;

        mView_dialog = View.inflate(context,R.layout.dialog_transaction_details,null);

        if (mDialog == null){
            // 创建AlertDialog对象
            mDialog = new AlertDialog.Builder(mContext).create();
            mDialog.show();
            // 设置点击可取消
            mDialog.setCancelable(true);
            // 获取Window对象
            Window window = mDialog.getWindow();
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            // 设置显示视图内容
            window.setContentView(mView_dialog);

//            WindowManager.LayoutParams lp = mDialog.getWindow().getAttributes();
//            lp.width = 500;// 调整该值可以设置对话框显示的宽度
//            lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
//            window.setAttributes(lp);
        }else {
            mDialog.show();
        }

        initView();
        initListener();


    }

    private void initListener() {



    }

    private void initView() {

        mTvTitle = mDialog.findViewById(R.id.tvTitle);
        mTvStartTime = mDialog.findViewById(R.id.tvStartTime);
        mTvStopTime = mDialog.findViewById(R.id.tvStopTime);
        mTvTotalTime = mDialog.findViewById(R.id.tvTotalTime);

        mTvTitle.setText(mTransactionUseTime.getTransactionname());
        String startTime = DateUtils.timeMillisToTime("yyyy年MM月dd日 HH时mm分ss秒",mTransactionUseTime.getStarttime());
        mTvStartTime.setText("开始于："+startTime);
        String stopTime = DateUtils.timeMillisToTime("yyyy年MM月dd日 HH时mm分ss秒",mTransactionUseTime.getStoptime());
        mTvStopTime.setText("结束于："+stopTime);
        String totalTime = DateUtils.getTotalTime("yyyy年MM月dd日 HH时mm分ss秒",
                mTransactionUseTime.getStarttime(),mTransactionUseTime.getStoptime());
        mTvTotalTime.setText("本次任务功用时："+totalTime);


    }

    public void show(){
        mDialog.setCanceledOnTouchOutside(false);
//        mDialog.show();
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onClick(View view) {

        switch (view.getId()){

        }

    }


//    public void setHandler(Handler handler) {
//        this.mHandler = handler;
//    }
}
